﻿using System;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UserNotificationAspMvc;
using UserNotificationAspMvc.Models;

namespace NotificationsUnitTests
{
    [TestClass]
    public class NotificationsHelperTests
    {
        [TestMethod]
        public void NotificationHelperDoesntRenderZeroWidthNotifications()
        {
            //arrange
            NotificationQueue queue = new NotificationQueue();
            UserNotification error = new UserNotification("Error message generated by alex",NotificationType.Error,autoClose : 2200,width : 0);
            
            //act
            queue.Notifications.Add(error);

            var viewcontext = new ViewContext();
            viewcontext.HttpContext = new FakeHttpContext();
            var idata = new FakeIView();
            HtmlHelper helper = new HtmlHelper(viewcontext, idata);
            var helperReturn = UserNotificationAspMvc.HtmlHelpers.DisplayHelper.RenderNotificationsList(helper, queue);

            //assert
            Assert.IsFalse(helperReturn.ToString().Contains(error.NotificationId.ToString()));
        }
        [TestMethod]
        public void NotificationHelperReturnsEmptyStringWhenNoNotifications()
        {
            //arrange
            NotificationQueue queue = new NotificationQueue();
            
            //act
            queue.Notifications = null; ;
            var viewcontext = new ViewContext();
            viewcontext.HttpContext = new FakeHttpContext();
            var idata = new FakeIView();
            HtmlHelper helper = new HtmlHelper(viewcontext, idata);
            var helperReturn = UserNotificationAspMvc.HtmlHelpers.DisplayHelper.RenderNotificationsList(helper, queue);


            //assert
            Assert.IsTrue(string.IsNullOrEmpty(helperReturn.ToString()));
        }
    }
}
